package com.lanxiaoye.shoppingSystem.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ������
 * Created by LDL on 2016/6/7.
 */
public class Util {
	
	private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	
	/**
	 * ��ʱ���ת��Ϊ(yyyy-MM-dd)��ʽ���ַ���
	 * @param timestamp
	 * @return
	 */
	public static String timestampToStr(long timestamp) {
		return sdf.format(new Date(timestamp * 1000));
	}
	
	/**
	 * ��(yyyy-MM-dd)��ʽ���ַ���ת��Ϊʱ���
	 * @param dateStr
	 * @return
	 */
	public static long strToTimestamp(String dateStr) {
		try {
			Date date = sdf.parse(dateStr);
			return date.getTime() / 1000;
		} catch (ParseException e) {
			System.out.println(e.getMessage());
			return 0;
		}
	}
	
	/**
	 * ����ַ����Ƿ�����հ��ַ�,nullʱҲ����true
	 * @param str
	 * @return
	 */
	public static boolean containBlank(String str) {
		if (str == null)
			return true;
		return str.length() != str.replaceAll("\\s*", "").length();
	}
}
